﻿namespace homework5_Hanoi
{
    internal class Program
    {
        /// <summary>
        /// 汉诺塔
        /// </summary>
        /// <param name="n"></param>
        /// <param name="A"></param>
        /// <param name="B"></param>
        /// <param name="C"></param>
        public static void Hanoi(int n, char A, char B, char C)
        {
            //只有一层时，直接将其从塔A移动到塔C
            if (n == 1)
                Console.WriteLine($"将第{n}个盘子从塔{A}移动到塔{C}");
            else
            {
                //递归调用Hanoi
                //将n-1层从塔A经过塔C移动到塔B
                Hanoi(n - 1, A, C, B);
                //将第n层从塔A移动到塔C
                Console.WriteLine($"将第{n}个盘子从塔{A}移动到塔{C}");
                //将n-1层从塔B经塔A移动到塔C
                Hanoi(n - 1, B, A, C);
            }
        }
        static void Main(string[] args)
        {
            //输入层数
            Console.WriteLine("请输入盘子个数");
            string input = Console.ReadLine();
            int num = int.Parse(input);
            //调用Hanoi
            Hanoi(num, 'A', 'B', 'C');
        }
    }
}